var const_CurID;
var fnCustomAdd=null, fnCustomEdit=null;
//alert((this.location.href.indexOf("DataGrid") <= 0 && this.location.href.indexOf("YUI") <= 0));
if (this.location.href.indexOf("DataGrid") <= 0 || this.location.href.indexOf("YUI") <= 0) {
      fnCustomAdd = function () {

        document.getElementById("EditUIWindow").src = "/Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=SysFunction&pid=" + const_CurID;
        var _btn = document.getElementById("yui-gen7-button");
        if (_btn != null && _btn != undefined) {
            _btn.style.display = "block";
        }

        SetMaxDWH(YAHOO.example.container.dialog1);
        YAHOO.example.container.dialog1.show();
    }


     fnCustomEdit = function () {
        document.getElementById("EditUIWindow").src = "/Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=SysFunction&id=" + const_CurID;
        var _btn = document.getElementById("yui-gen7-button");
        if (_btn != null && _btn != undefined) {
            _btn.style.display = "block";
        }
        SetMaxDWH(YAHOO.example.container.dialog1);
        YAHOO.example.container.dialog1.show();
    }
}
var fnCustomDelete = function () {
    //依赖于jQuery.Data.js
    var data = fnGetData("SysFunction", "ParentID='" + const_CurID + "'");
    if (data != null && data.length > 0) {
        alter("还有子模块，不能直接删除!");
        return;
    }
    SaveUrl = "AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + const_CurID;
    YAHOO.example.container.dialog3.show();
}

//删除
function DeleteData() {
    if (typeof (fnCustomDeleteData) == "function") {
        fnCustomDeleteData();
        return;
    } else {
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;

                    if (str == "1") {
                        alert("数据删除成功");
                        var recordID = mDataTable.getSelectedRows()[0];
                        if (dl.length == 0) {
                            mDataTable.deleteRow(recordID);
                        }
                        else {
                            for (var i = 0; i < dl.length; i++) {
                                mDataTable.deleteRow(dl[i]);
                            }
                        }
                    }
                    else {
                        alert(str + "\n" + "数据删除失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
        YAHOO.example.container.dialog3.hide();
    }
}

var fnCustomCheck = function () {
    var entity = instance[0];
    var msg = "";
    if (entity.Name == "") {
        msg = msg + "模块名称不能空;/r/n";
    }
    if (entity.FunctionId == entity.ParentID) {
        msg = msg + "父级模块不能选择自己！"
    }
    return msg;
}

//alert("");
$(document).ready(function () {
    if (typeof (getPar1) == "function") {
        var _pid = getPar1("pid");
        if (_pid != "") {
            GetData("ParentID", _pid);
        }
    }
});


function fnCallBack(o) {
    //debugger
    AddNewNode(o.FunctionId, o.Name);
}

function _CallBack() {
    parent.fnCallBack(instance[0]);
}